package com.ruoyi.pidaijiData.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.calculate.BezierCurveUtil;
import com.ruoyi.pidaijiData.domain.plat.DataPidaijiJxtd;
import com.ruoyi.pidaijiData.mapper.DataPidaijiJxtdMapper;
import com.ruoyi.pidaijiData.service.IDataPidaijiJxtdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 皮带机径向跳动测试数据Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-04
 */
@Service
public class DataPidaijiJxtdServiceImpl implements IDataPidaijiJxtdService
{
    @Autowired
    private DataPidaijiJxtdMapper dataPidaijiJxtdMapper;

    /**
     * 查询皮带机径向跳动测试数据
     * 
     * @param jxId 皮带机径向跳动测试数据主键
     * @return 皮带机径向跳动测试数据
     */
    @Override
    public DataPidaijiJxtd selectDataPidaijiJxtdByJxId(Long jxId)
    {
        return dataPidaijiJxtdMapper.selectDataPidaijiJxtdByJxId(jxId);
    }

    /**
     * 查询皮带机径向跳动测试数据列表
     * 
     * @param dataPidaijiJxtd 皮带机径向跳动测试数据
     * @return 皮带机径向跳动测试数据
     */
    @Override
    public List<DataPidaijiJxtd> selectDataPidaijiJxtdList(DataPidaijiJxtd dataPidaijiJxtd)
    {
        return dataPidaijiJxtdMapper.selectDataPidaijiJxtdList(dataPidaijiJxtd);
    }

    /**
     * 查询皮带机径向跳动测试数据
     *
     * @param dataTaskId
     * @return 皮带机径向跳动测试数据
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataPidaijiJxtd>> selectDataPidaijiJxtdByDataTaskId(Long dataTaskId) {
        List<DataPidaijiJxtd> dataPidaijiJxtds = dataPidaijiJxtdMapper.selectDataPidaijiJxtdByDataTaskId(dataTaskId);
        if (!dataPidaijiJxtds.isEmpty()) {
            dataPidaijiJxtds.forEach(item -> {
                if (item.getWyList() != null) {
                    // 速度曲线数据
                    item.setWyChartLineDTO(BezierCurveUtil.calPoints(item.getWyList(), 0.1f, true));
                }
            });
        }
        return new AsyncResult<>(dataPidaijiJxtds);
    }

    /**
     * 新增皮带机径向跳动测试数据
     *
     * @param dataPidaijiJxtds 皮带机径向跳动测试数据
     * @return 结果
     */
    @Override
    public int batchDataPidaijiJx(List<DataPidaijiJxtd> dataPidaijiJxtds) {
        return dataPidaijiJxtdMapper.batchDataPidaijiJx(dataPidaijiJxtds);
    }

    /**
     * 修改皮带机径向跳动测试数据
     *
     * @param dataTaskId
     * @return 结果
     */
    @Override
    public int updateDataPidaijiJxByDataTaskId(Long dataTaskId) {
        return 0;
    }

    /**
     * 修改皮带机径向跳动测试数据
     *
     * @param jxId
     * @return 结果
     */
    @Override
    public int updateDataPidaijiJxtdByJxId(Long jxId) {
        return dataPidaijiJxtdMapper.updateDataPidaijiJxtdByJxId(jxId);
    }

    /**
     * 新增皮带机径向跳动测试数据
     * 
     * @param dataPidaijiJxtd 皮带机径向跳动测试数据
     * @return 结果
     */
    @Override
    public int insertDataPidaijiJxtd(DataPidaijiJxtd dataPidaijiJxtd)
    {
        dataPidaijiJxtd.setCreateTime(DateUtils.getNowDate());
        return dataPidaijiJxtdMapper.insertDataPidaijiJxtd(dataPidaijiJxtd);
    }

    /**
     * 修改皮带机径向跳动测试数据
     * 
     * @param dataPidaijiJxtd 皮带机径向跳动测试数据
     * @return 结果
     */
    @Override
    public int updateDataPidaijiJxtd(DataPidaijiJxtd dataPidaijiJxtd)
    {
        dataPidaijiJxtd.setUpdateTime(DateUtils.getNowDate());
        return dataPidaijiJxtdMapper.updateDataPidaijiJxtd(dataPidaijiJxtd);
    }

    /**
     * 批量删除皮带机径向跳动测试数据
     * 
     * @param jxIds 需要删除的皮带机径向跳动测试数据主键
     * @return 结果
     */
    @Override
    public int deleteDataPidaijiJxtdByJxIds(Long[] jxIds)
    {
        return dataPidaijiJxtdMapper.deleteDataPidaijiJxtdByJxIds(jxIds);
    }

    /**
     * 删除皮带机径向跳动测试数据信息
     * 
     * @param jxId 皮带机径向跳动测试数据主键
     * @return 结果
     */
    @Override
    public int deleteDataPidaijiJxtdByJxId(Long jxId)
    {
        return dataPidaijiJxtdMapper.deleteDataPidaijiJxtdByJxId(jxId);
    }
}
